package com.zzzy.controller;


import com.zzzy.po.User;
import com.zzzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping( value = "/user/{id}")
    public User getUser(@PathVariable("id") int id, HttpServletRequest request){
        User user = userService.findUser( id);

        return user;
    }

    @ResponseBody
    @RequestMapping( value = "/user/add")
    public String getUser(){
        User user = new User();
        user.setName("Jimmy");
        user.setAge(20);

        userService.addUser(user);

        return "add user";
    }


    @ResponseBody
    @RequestMapping( value = "/login/{tenent}")
    public String tenentLogin(@PathVariable("tenent") String tenent, HttpServletRequest request){

        request.getSession().setAttribute("tenent", tenent);
        return "租户‘" +tenent+"’登录成功 <a href='/user/1'>user1</a> <a href='/user/2'>user2</a> ";
    }


}
